/*
 * @Author: xiezuobing(948466)[435321508@qq.com] 
 * @Date: 2017-12-18 10:11:54 
 * @Last Modified by: xiezuobing
 * @Last Modified time: 2017-12-26 11:27:32
 */

(function() {

  //设为管理员和普通用户
  setUserType();
  function setUserType() {
    $('.setUserType').each(function() {
      $(this).click(function() {
        var userId = $(this).attr('userId');
        var userType = parseInt($(this).attr('userType'));
        $.ajax({
          method: 'post',
          url: '/admin/user/editUserType',
          data: {
            userId: userId,
            userType: Math.abs(userType - 1)
          },
          dataType: 'json',
          headers: {
            "x-csrf-token": $('#csrf-token').val()
          },
          success: function(data) {
            toastProp(data);
          },
          fail: function(err) {
            console.log(err);
          }
        });
      });
    });
  }

  //搜索相关
  searchHandler();
  function searchHandler() {
    var queryArr = [
      $('select[name="orderBy"]'),
      $('select[name="order"]'),
      $('input[name="keyword"]')
    ];
    var submitButton = $("#submitSearch");
    var options = getQueryObject();
    delete options['pageSize'];
    delete options['pageNo'];
    submitButton.click(function() {
      $(queryArr).each(function() {
        var key = this.attr("name");
        options[key] = this.val();
      })
      window.location.href = getUrlByQuery(options)
    });
    $(document).keydown(function(e) {
      if (e.keyCode == 13) submitButton.click();
    })
  }

}())